/*
 * @Author: zshawk1982
 * @Date: 2021-09-23 10:01:22
 * @LastEditTime: 2022-11-13 16:45:14
 * @LastEditors: zshawk1982
 * @Description:
 * @FilePath: \media_web_client\src\utils\request.js
 */

import axios from "axios";
//创建实例
const instance = axios.create({
  // baseURL: "http://47.242.95.106:8081",
  baseURL: "http://localhost:3000",
  timeout: 1000,
});

//添加请求拦截器
instance.interceptors.request.use(
  function (config) {
    // 在发送请求之前做些什么
    if (config.url != "/user/login") {
      const { accessToken } = JSON.parse(localStorage.getItem("userInfo"));
      config.headers.Authorization = accessToken;
    }
    return config;
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

export default instance;
